package com.ruoyi.web.controller.custom;

import java.util.List;

import com.ruoyi.system.domain.Pay;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SalaryBaseV1;
import com.ruoyi.system.service.ISalaryBaseV1Service;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 员工薪资v1.0Controller
 * 
 * @author ruoyi
 * @date 2021-09-10
 */
@Controller
@RequestMapping("/system/v1")
public class SalaryBaseV1Controller extends BaseController
{
    private String prefix = "system/v1";

    @Autowired
    private ISalaryBaseV1Service salaryBaseV1Service;

    @RequiresPermissions("system:v1:view")
    @GetMapping()
    public String v1()
    {
        return prefix + "/v1";
    }

    /**
     * 查询员工薪资v1.0列表
     */
    @RequiresPermissions("system:v1:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SalaryBaseV1 salaryBaseV1)
    {
        startPage();
        List<SalaryBaseV1> list = salaryBaseV1Service.selectSalaryBaseV1List(salaryBaseV1);
        return getDataTable(list);
    }

    /**
     * 导出员工薪资v1.0列表
     */
    @RequiresPermissions("system:v1:export")
    @Log(title = "员工薪资v1.0", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SalaryBaseV1 salaryBaseV1)
    {
        List<SalaryBaseV1> list = salaryBaseV1Service.selectSalaryBaseV1List(salaryBaseV1);
        ExcelUtil<SalaryBaseV1> util = new ExcelUtil<SalaryBaseV1>(SalaryBaseV1.class);
        return util.exportExcel(list, "员工薪资v1.0数据");
    }

    /**
     * 新增员工薪资v1.0
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工薪资v1.0
     */
    @RequiresPermissions("system:v1:add")
    @Log(title = "员工薪资v1.0", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SalaryBaseV1 salaryBaseV1)
    {
        return toAjax(salaryBaseV1Service.insertSalaryBaseV1(salaryBaseV1));
    }

	@PostMapping("/import")
	@Log(title = "员工薪资v1.0", businessType = BusinessType.IMPORT)
	@ResponseBody
	public AjaxResult importSalary(MultipartFile file)throws Exception
	{
		ExcelUtil<SalaryBaseV1> salaryBaseV1ExcelUtil = new ExcelUtil<>(SalaryBaseV1.class);
		List<SalaryBaseV1> list = salaryBaseV1ExcelUtil.importExcel(file.getInputStream());
		if(list != null && list.size()>0){
			list.stream().forEach(salary -> salaryBaseV1Service.insertSalaryBaseV1(salary));
		}
		return AjaxResult.success("导入成功!");
	}

	@GetMapping("/importTemplate")
	@ResponseBody
	public AjaxResult importTemplate()
	{
		ExcelUtil<SalaryBaseV1> util = new ExcelUtil<>(SalaryBaseV1.class);
		return util.importTemplateExcel("员工薪酬组成表");
	}

    /**
     * 修改员工薪资v1.0
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SalaryBaseV1 salaryBaseV1 = salaryBaseV1Service.selectSalaryBaseV1ById(id);
        mmap.put("salaryBaseV1", salaryBaseV1);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工薪资v1.0
     */
    @RequiresPermissions("system:v1:edit")
    @Log(title = "员工薪资v1.0", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SalaryBaseV1 salaryBaseV1)
    {
        return toAjax(salaryBaseV1Service.updateSalaryBaseV1(salaryBaseV1));
    }

    /**
     * 删除员工薪资v1.0
     */
    @RequiresPermissions("system:v1:remove")
    @Log(title = "员工薪资v1.0", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(salaryBaseV1Service.deleteSalaryBaseV1ByIds(ids));
    }
}
